fix: prevent mismatch error with default namespace on ancestor queries#604
fix: prevent mismatch error with default namespace on ancestor queries#604cguardia wants to merge 1 commit into
Conversation
| entity3.put() | ||
| dispose_of(entity3.key._key) | ||
|
|
||
| with client_context.new(namespace=other_namespace).use(): |
There was a problem hiding this comment.
FWIW, tests are not, by default, run in the default namespace, so you don't really have to switch namespace here. It's already not the default. Although, I guess it might make it more readable to show that the namespace is different explicitly.
chrisrossi
left a comment
There was a problem hiding this comment.
See my note about passing namespace to the model constructor.
| parent_key = entity1.put() | ||
| dispose_of(entity1.key._key) | ||
|
|
||
| entity2 = Dummy(foo="child", parent=parent_key, namespace=None) |
There was a problem hiding this comment.
I noticed in the customer's example that they don't explicitly pass namespace. I would think that the namespace would be implied by passing in parent. For grins, I tried removing the namespace arg from this test and I get a namespace mismatch exception in the model constructor. Is there maybe a little more work to do here?
There was a problem hiding this comment.
Well, I confess I added this to make the test pass, but the customer's code does run unchanged if using a python script outside of the test machinery. Maybe I'm missing something on the test setup?
There was a problem hiding this comment.
It looks like it's just because in the customer's example the context's namespace is still the default namespace when that entity is created, so there won't be a mismatch between entity2 and its parent. Does still seem like specifying parent should imply the namespace, though.
I know you're starting your new job. Would you like me to take this one?
There was a problem hiding this comment.
Yes, please take this. I appreciate the offer.
FWIW, the following code caused the mismatch error before the fix was applied, and it works fine with the fix in:
import os
from google.cloud import ndb
class Dummy(ndb.Model):
foo = ndb.StringProperty(default='')
with ndb.Client().context():
entity1 = Dummy(foo='bar', namespace='')
entity1.put()
key_entity1 = entity1.key
entity2 = Dummy(foo='child', parent=key_entity1)
entity2.put()
entity3 = Dummy(foo='childless')
entity3.put()
with ndb.Client().context(namespace='other_context'):
l = Dummy.query(ancestor=key_entity1, namespace='').fetch()
for e in l:
print(e)
I couldn't quite duplicate that in the text.
|
Superceded by #614 |
fixes #577